import 'package:flutter/material.dart';
import 'package:flutter_slidable/flutter_slidable.dart';
import 'package:tender_flutter/constant/theme_colors.dart';
import 'package:tender_flutter/page/home/model/tender_entity.dart';
import 'package:tender_flutter/utils/screen_adaper.dart';

class CollectionTenderListCell extends StatefulWidget {
  const CollectionTenderListCell(
      {Key key, this.data, this.onCancelCallback, this.onClickCallback})
      : super(key: key);

  final TenderList data;
  final GestureTapCallback onCancelCallback;
  final GestureTapCallback onClickCallback;

  @override
  _CollectionTenderListCellState createState() =>
      _CollectionTenderListCellState();
}

class _CollectionTenderListCellState extends State<CollectionTenderListCell> {
  @override
  Widget build(BuildContext context) {
    return Slidable(
        actionPane: SlidableDrawerActionPane(),
        actionExtentRatio: 0.2,
        secondaryActions: <Widget>[
          IconSlideAction(
            caption: '取消收藏',
            color: ThemeColors.colorType30,
            icon: Icons.cancel,
            onTap: widget.onCancelCallback,
          ),
        ],
        child: _initCell());
  }

  Widget _initCell() {
    return GestureDetector(
      onTap: widget.onClickCallback,
      child: Container(
        color: ThemeColors.colorWhite,
        padding: EdgeInsets.all(ScreenAdapter.width(30)),
        child: Container(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            mainAxisAlignment: MainAxisAlignment.start,
            mainAxisSize: MainAxisSize.min,
            children: <Widget>[
              Text(
                widget.data.title,
                maxLines: 2,
                softWrap: true,
                overflow: TextOverflow.ellipsis,
                style: TextStyle(
                    color: ThemeColors.colorType1,
                    fontSize: ScreenAdapter.sp(32),
                    fontWeight: FontWeight.w500),
              ),
              SizedBox(height: ScreenAdapter.height(15)),
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: <Widget>[
                  Row(
                    children: <Widget>[
                      Container(
                        margin: EdgeInsets.only(right: ScreenAdapter.width(20)),
                        padding: EdgeInsets.symmetric(
                            horizontal: ScreenAdapter.width(20),
                            vertical: ScreenAdapter.width(10)),
                        child: Text(
                            _getTagOne(),
                            style: TextStyle(
                                color: ThemeColors.colorType40,
                                fontSize: ScreenAdapter.sp(24))),
                        decoration: BoxDecoration(
                            color: ThemeColors.colorType20,
                            borderRadius: new BorderRadius.circular(3)),
                      ),
                      widget.data.industry != null
                          ? Container(
                              padding: EdgeInsets.symmetric(
                                  horizontal: ScreenAdapter.width(20),
                                  vertical: ScreenAdapter.width(10)),
                              decoration: BoxDecoration(
                                  color: ThemeColors.colorType15,
                                  borderRadius: new BorderRadius.circular(3)),
                              child: Text(widget.data.industry ?? "",
                                  style: TextStyle(
                                      color: ThemeColors.colorType16,
                                      fontSize: ScreenAdapter.sp(24))),
                            )
                          : Container(),
                    ],
                  ),
                  Text(widget.data.date ?? "",
                      style: TextStyle(
                          color: ThemeColors.colorType1,
                          fontSize: ScreenAdapter.sp(24))),
                ],
              )
            ],
          ),
        ),
      ),
    );
  }
  /// 获取标签
  String _getTagOne(){
    if (widget.data.address != null && !widget.data.address.isEmpty){
      return widget.data.address;
    }
    if (widget.data.companyName != null && !widget.data.companyName.isEmpty){
      return widget.data.companyName;
    }
    if (widget.data.biddingClass != null && !widget.data.biddingClass.isEmpty){
      return widget.data.biddingClass;
    }
  }
}
